package accs.product.update;

public final class Version implements Comparable<Version> {
	public static final Version CURRENT_VERSION=new Version(0,5);
	
	private int minor;
	private int major;
	
	public Version(int major, int minor) {
		this.major=major;
		this.minor=minor;
	}
	
	public Version(String string) {
		int index=string.indexOf(".");
		
		major=Integer.parseInt(string.substring(0,index));
		minor=Integer.parseInt(string.substring(index+1));
	}

	public int getMinor() {
		return minor;
	}

	public int getMajor() {
		return major;
	}
	
	public String toString() {
		return major+"."+minor;
	}
	
	public boolean equals(Object obj) {
		if(!(obj instanceof Version)) return false;
		
		Version other=(Version)obj;
		return this.minor==other.minor && this.major==other.major;
	}

	public int compareTo(Version other) {
		int majorCompare=new Integer(this.major).compareTo(new Integer(other.major));
		if(majorCompare==0) {
			return new Integer(this.minor).compareTo(new Integer(other.minor));
		} else {
			return majorCompare;
		}
		//return new Integer(major*1000+minor).compareTo(new Integer(other.major*1000+other.minor));
	}
}